package com.spyz.hdfs_api;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.*;

import java.net.URI;
import java.util.Arrays;

public class P6_Hdfs_api_ll_2 {
    public static void main(String[] args) throws Exception {

        URI uri = new URI("hdfs://master:8020");

        Configuration conf = new Configuration();
        conf.set("dfs.replication","2");

        String user = "root";

        FileSystem fs = FileSystem.get(uri, conf,user);

        // TODO 判断文件还是文件夹
        FileStatus[] fileStatuses = fs.listStatus(new Path("/input"));
        for (FileStatus fileStatus : fileStatuses) {

            // .isFile()：判断是否是文件
            if (fileStatus.isFile()) {
                System.out.println("文件：" + fileStatus.getPath().getName());
            } else {
                System.out.println("文件夹：" + fileStatus.getPath().getName());
            }

        }

        fs.close();
    }
}
